package com.hjm.project.cardBag.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.cardBag.domain.CardBag;
import com.hjm.project.cardBag.service.ICardBagService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 卡包Controller
 * 
 * @author maker-platform
 * @date 2021-04-14
 */
@Controller
@RequestMapping("/cardBag/cardBag")
public class CardBagController extends BaseController
{
    private String prefix = "cardBag/cardBag";

    @Resource
    private ICardBagService cardBagService;

    @RequiresPermissions("cardBag:cardBag:view")
    @GetMapping()
    public String cardBag()
    {
        return prefix + "/cardBag";
    }

    /**
     * 查询卡包列表
     */
    @RequiresPermissions("cardBag:cardBag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CardBag cardBag)
    {
        startPage();
        List<CardBag> list = cardBagService.selectCardBagList(cardBag);
        return getDataTable(list);
    }

    /**
     * 导出卡包列表
     */
    @RequiresPermissions("cardBag:cardBag:export")
    @Log(title = "卡包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CardBag cardBag)
    {
        List<CardBag> list = cardBagService.selectCardBagList(cardBag);
        ExcelUtil<CardBag> util = new ExcelUtil<CardBag>(CardBag.class);
        return util.exportExcel(list, "cardBag");
    }

    /**
     * 新增卡包
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡包
     */
    @RequiresPermissions("cardBag:cardBag:add")
    @Log(title = "卡包", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CardBag cardBag)
    {
        return toAjax(cardBagService.insertCardBag(cardBag));
    }

    /**
     * 修改卡包
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CardBag cardBag = cardBagService.selectCardBagById(id);
        mmap.put("cardBag", cardBag);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡包
     */
    @RequiresPermissions("cardBag:cardBag:edit")
    @Log(title = "卡包", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CardBag cardBag)
    {
        return toAjax(cardBagService.updateCardBag(cardBag));
    }

    /**
     * 删除卡包
     */
    @RequiresPermissions("cardBag:cardBag:remove")
    @Log(title = "卡包", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cardBagService.deleteCardBagByIds(ids));
    }
}
